<?php

namespace app\api\controller\xykeep;
use app\common\controller\Api;

use app\api\model\xykeep\goods\Order as GoodsOrderModel;


/**
 * XYkeep 商城订单接口
 */
class GoodsOrder extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];
    

    /**
	 * 列表
	 */
	public function lists()
    {
    	$params = $this->request->post();
        $data = GoodsOrderModel::getLists($params);
        $this->success('商品订单', $data);
    }

    /**
	 * 加载（确认订单数据）
	 */
	public function init()
    {
    	$params = $this->request->post();
        $data = GoodsOrderModel::getInitData($params);
        $this->success('订单数据', $data);
    }

    /**
     * 创建
     */
	public function add()
    {
        $params = $this->request->post();
        $order = GoodsOrderModel::addOrder($params);
        $this->success('订单创建成功', $order);
    }

    /**
     * 详情
     */
    public function detail()
    {
        $params = $this->request->post();
        $this->success('课程订单详情', GoodsOrderModel::getDetail($params));
    }

    public function cancel()
    {
        $params = $this->request->post();
        $this->success('取消成功', GoodsOrderModel::cancelOrder($params));
    }


    /**
     * 物流查询
     */
    public function logistics()
    {
        $params = $this->request->post();
        $this->success('物流查询', GoodsOrderModel::getLogistics($params));
    }

    /**
     * 确认收货
     */
    public function take_delivery(){
        $params = $this->request->post();
        $this->success('收货成功', GoodsOrderModel::takeDelivery($params));
    }

    /**
     * 申请退款
     */
    public function refund()
    {
        $params = $this->request->post();
        $info = GoodsOrderModel::where(['id'=>$params['id']])->find();
        if(!in_array($info['status'],[1,2,3])){
            $this->error('订单状态错误');
        }
        $info->refund_before = $info['status'];
        $info->status = 4;
        $info->save();
        $this->success('申请退款');
    }
	
}